/**
 * 路由配置文件
 */
//导入组件
import Vue from 'vue'
import Router from 'vue-router'
import Index from '../components/index.vue'
import NotFound from '../components/notfound.vue'
import Login from '../view/login.vue'
import Settle from '../view/settle.vue'
import Root from '../view/root.vue'
import Rank from '../navview/rank.vue'
import User from "../navview/user.vue"
import State from "../navview/userstate.vue"
import Commodity from "../navview/commodity.vue"
import Cygrounding from "../navview/cygrounding.vue"
import CommodityType from "../navview/commoditytype.vue"
//安装路由
Vue.use(Router)
//配置路由
export default new Router({
  mode: 'history',
  routes:[
    //设置项目启动默认显示页面
    {
      path:"/",
       component:Index
    },
    {
      path:'/index',
      component:Index
    },
    {
      path:'/login',
      component:Login
    },
    {
      path:'/settle',
      component:Settle
    },
    {
      path:'/root',
      component:Root,
	  beforeEnter(to,from,next){
		if(sessionStorage.getItem("user") != null && JSON.parse(sessionStorage.getItem("user")).role == 2){
			next();
		}else{
			next('/index')
		}
		},
		 redirect:{name:"user"},
		children:[
			{
				path:"/root/user",
				name:"user",
				component:User,
			},
			{
				path:"/root/userrank",
				name:"userrank",
				component:Rank,
			},
			{
				path:"/root/state",
				name:"state",
				component:State,
			},
			{
				path:"/root/commodity",
				name:"commodity",
				component:Commodity,
			},
			{
				path:"/root/cygrounding", //商品上下架路由路径
				name:"cygrounding",
				component:Cygrounding
			},
			{
				path:"/root/commoditytype", //商品上类型路由路径
				name:"commoditytype",
				component:CommodityType
			},
		]
    },
   {
     path:'*',
     component:NotFound
   }
  ]
})
